import 'package:sleep/db/sql_base.dart';

class SQLManger {
  static SQLManger? _manger;
  SQLManger._();
  static SQLManger share() {
    _manger ??= SQLManger._();
    return _manger!;
  }

  final SqlBase helper = SqlBase();
  final Map buffer = {};

  init() async {
    await helper.open();
    final allData = await helper.getAll();
    buffer.addEntries(allData.entries);
  }

  save({
    required String key,
    required String value,
  }) {
    buffer[key] = value;
    helper.save(key: key, value: value);
  }

  String? get({required String key}) {
    return buffer[key];
  }

  delete(String key) {
    buffer.remove(key);
    helper.delete(key);
  }
}
